package dt.inlee.common.util;

import java.util.Random;

/**
 * 颜色工具
 * 
 * @author chenyanbo
 * @version 2014-06-05
 */
public class ColorUtil {


    /**
     * 随机生成16进制颜色
     * 
     * @param num
     * @return
     */
    public static String randomColor(int num) {
        String r, g, b;
        Random random = new Random();
        r = Integer.toHexString(random.nextInt(256)).toUpperCase();
        g = Integer.toHexString(random.nextInt(256)).toUpperCase();
        b = Integer.toHexString(random.nextInt(256)).toUpperCase();

        r = r.length() == 1 ? "0" + r : r;
        g = g.length() == 1 ? "0" + g : g;
        b = b.length() == 1 ? "0" + b : b;
        return r + g + b;
    }


    /**
     * 根据算法生成16进制颜色
     * 
     * @param num
     * @return
     */
    public static String trans(int num) {
        int param = 3112233;// 系数
        num = num * param;
        String str = Integer.toHexString(num);
        str = str.substring(str.length() - 6, str.length());
        return str;
    }

}
